/******************************************************************************
	This file is a part of the Snapshot Bioinformatics Project

	Copyright (C) 2012-2013 Jarom Schow

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#ifndef SNAPSHOT_UI_H
#define SNAPSHOT_UI_H

#include <QtWidgets/QMainWindow>

#include "SqlServer.h"

class QLabel;
class QLineEdit;
class QPushButton;
class QSplitter;
class QTreeView;

class SnapshotGeneCollection;
class SnapshotGeneProxyModel;
class SnapshotTree;
class SnapshotTreeProxyModel;
class SnapshotTreeView;

class SnapshotUI : public QMainWindow {
	Q_OBJECT
	friend class Snapshot;
public:
	SnapshotUI();
	virtual ~SnapshotUI();

	virtual bool	event( QEvent *e );

	bool	getIgnoreEmpty() const;
	void	setIgnoreEmpty( bool onOff );

	bool	getIgnoreUnclassified() const;
	void	setIgnoreUnclassified( bool onOff );

	bool	getIgnoreEnvSamp() const;
	void	setIgnoreEnvSamp( bool onOff );

	SnapshotTree*			getTaxonomy() const;
	SnapshotGeneCollection*	getGenes() const;

public slots:

	void	clearAll();

private slots:

	void	dbSettings();
	void	dbWizard();
	void	loadSeqFiles();
	void	loadGenBank();
	void	updateTaxonomy();
	void	addTaxon();
	void	exportSequences();
	void	exportAccessions();
	void	updateCoverages();
	void	about();
	void	goWiki();
	void	goQuickStart();
	void	viewLogFile();
	void	preferences();
	void	information();
	void	followLink( const QString &url );

protected:

	virtual void	closeEvent( QCloseEvent *e );

private:

	void	init();
	void	buildMainMenu();
	void	buildUI();
	void	setOnlineHelp();
	void	restoreUI();
	void	saveUI();
	int		getTaxonFromUser();
	int		findTaxonByName( const QString &name );
	bool	connectToDB( Bio::SqlServerSettings settings );
	bool	createDB( Bio::SqlServerSettings settings );
	bool	checkEmbeddedConfigFile( const QString &filename );
	QString	getDefaultEmbeddedConfigFile() const;
	bool	loadSeqFile( const QString &filename );

	QPushButton				*m_addBtn;
	QSplitter				*m_splitter;
	QLabel					*m_dbStatusLbl;
	SnapshotTree			*m_taxonomy;
	SnapshotTreeProxyModel	*m_taxonModel;
	SnapshotTreeView		*m_taxonView;
	SnapshotGeneCollection	*m_genes;
	SnapshotGeneProxyModel	*m_geneModel;
	QTreeView				*m_geneView;
	Bio::SqlServer			*m_server;
};

#endif // SNAPSHOT_UI_H